package com.lovo.psc.controller;

import com.lovo.psc.bean.VendorProductBean;
import com.lovo.psc.service.IVendorProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("product")
public class VendorProductController {

    @Autowired
    private IVendorProductService service;

    @GetMapping("findAll")
    public List<VendorProductBean> findAll(){
        return service.findAll();
    }

    @GetMapping("findByName/{name}")
    private VendorProductBean findByName(@PathVariable("name") String name){
        return service.findByName(name);
    }
    /**
     * 查询所有类型
     * @return 类型集合
     */
    @RequestMapping("findTypeLst")
    List<VendorProductBean> findTypeLst() {
        return service.findTypeLst();
    }

    @RequestMapping("findAllProduct/{id}")
    public List<VendorProductBean> findAll(@PathVariable("id") int id) {
        List<VendorProductBean> all = service.findAllProduct(id);
        return all;
    }

    /**
     * 根据类型查询所以商品
     *
     * @param type
     * @return
     */
    @RequestMapping("findProductTypeLst/{type}")
    List<VendorProductBean> findProductTypeLst(@PathVariable("type") String type) {
        return service.findProductTypeLst(type);
    }

    /**
     * 增加新商品
     *
     * @param vendorproduct 商品集合
     */
    @RequestMapping("add")
    public String add(VendorProductBean vendorproduct) {
        service.add(vendorproduct);
        return "ok";
    }

    /**
     * 修改库存数量
     */
    @RequestMapping("update/{userId}/{number}")
    public String update(@PathVariable("userId") String userId,@PathVariable("number") int number){
        service.update(userId, number);
        return "ok";
    }
    @RequestMapping("del/{ber}")
    public String del(@PathVariable("ber") String ber) {
        service.del(ber);
        return "ok";
    }
}
